#!/bin/bash

readonly  BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $BASE_DIR || exit;

shopt -s expand_aliases
[ "$(uname)" == "Darwin" ] &&  alias date='gdate'


pwd
echo   $BASE_DIR"/sql.sh"
source  $BASE_DIR"/sql.sh"

CONFIG_FILE=$BASE_DIR/prod.conf
start='2024-08-01'

year_month=$(date -d  "${start}" +%Y%m)   #  yyyy-MM-dd  ==>  yyyymm
day=$(date -d "$start" +%d)            #  yyyy-MM-dd   ==> dd
echo "[$(date)] executing  ${year_month}/${day}"

cp   /opt/trx-data-importer/data/trx-data-files/gx/${year_month}/${day}/merrecord_V2.zip     /opt/trx-data-importer/data/trx-data-files/gx/${year_month}/${day}/merrecord_V2_history_all.zip
cp   /opt/trx-data-importer/data/trx-data-files/gx/${year_month}/${day}/c_merrecord_V2.zip   /opt/trx-data-importer/data/trx-data-files/gx/${year_month}/${day}/c_merrecord_V2_history_all.zip



echo  "/opt/trx-data-importer/bin/console import -b gx  --environment=prod  -t  ${start} -f   /opt/trx-data-importer/data/trx-data-files/gx/${year_month}/${day}/merrecord_V2_history_all.zip "

echo  "/opt/trx-data-importer/bin/console import -b gx  --environment=prod  -t  ${start} -f   /opt/trx-data-importer/data/trx-data-files/gx/${year_month}/${day}/c_merrecord_V2_history_all.zip "

/opt/trx-data-importer/bin/console import -b gx  --environment=prod  -t  $start -f   /opt/trx-data-importer/data/trx-data-files/gx/$year_month/$day/merrecord_V2_history_all.zip
/opt/trx-data-importer/bin/console import -b gx  --environment=prod  -t  $start -f   /opt/trx-data-importer/data/trx-data-files/gx/$year_month/$day/c_merrecord_V2_history_all.zip




execute_sql=$SQL
execute_sql=${execute_sql//'#param'/$start}
echo  "executing...........      $execute_sql"
mysql --defaults-file=$CONFIG_FILE -e "$execute_sql"






